package com.macro.client.service.impl;

import com.macro.client.service.ProductService;
import com.macro.mall.mapper.PmsBrandMapper;
import com.macro.mall.mapper.PmsProductMapper;
import com.macro.mall.mapper.PmsSkuStockMapper;
import com.macro.mall.model.PmsBrand;
import com.macro.mall.model.PmsProduct;
import com.macro.mall.model.PmsSkuStock;
import com.macro.mall.model.ProductById;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ProductServiceImpl
 * @Description 描述
 * @Author bai
 * @Date 2024/10/22 21:43
 */

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    @Autowired
    private PmsProductMapper pmsProductMapper;

    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;

    @Override
    public ProductById fetchProductDetail(Integer id) {
        ProductById productById = new ProductById();
        PmsProduct pmsProduct = pmsProductMapper.selectByPrimaryKey(Long.valueOf(id));
        List<PmsSkuStock> pmsSkuStocks = pmsSkuStockMapper.selectByProductId(id);
        PmsBrand pmsBrand = pmsBrandMapper.selectByPrimaryKey(pmsProduct.getBrandId());
        productById.setBrand(pmsBrand.getName());
        productById.setProduct(pmsProduct);
        productById.setPmsSkuStockList(pmsSkuStocks);
        return productById;
    }
}
